//designpatterns.facade.NewCipherMachine.java
package org.patterns.structural.facade;

public class NewCipherMachine {
	public String encrypt(String plainText) {
		System.out.print("数据加密，将明文转换为密文：");
		String result = "";
		int key = 10;//设置密钥，移位数为10
		for (int i = 0; i < plainText.length(); i++) {
			char item = plainText.charAt(i);
			//小写字母移位
			if (item >= 'a' && item <= 'z') {
				item += key % 26;
			    if (item > 'z') item -= 26;
			    if (item < 'a') item += 26;
			}
            //大写字母移位
			if (item >= 'A' && item <= 'Z') {
				item += key % 26;
			    if (item > 'Z') item -= 26;
			    if (item < 'A') item += 26;
			}
			result += item;
		}
		System.out.println(result);
		return result;
	}
}
